Object Tracking / Driving to an Object
Resources
- Our Page on Object Distance Estimation
- Our Page on Autonomous Movement
Object Tracking
Driving to an Object
Our Way
Implement the following algorithm:
- Detect the object and store its bounding box (refer to the Machine Learning Toolchain module)
- Determine the distance from the object to the camera (refer to the Object Distance Estimation module). You will only need the distance on the z and x axis for this.
- You now have the hypotenuse (distance on the z-axis) and one side length (absolute value of the distance on the x-axis) of a right triangle! Solve for the other side length through the Pythagorean theorem. This second side is your y distance!
- Add the x (horizontal) and newly calculated y distance to your robot's current position, this is the object's real-world position. Note that you have to account for the robot's orientation!
- Plug the position into your autonomous movement functions (refer to the autonomous movement sections)
Alternative Methods
The FTC samples also give an excellent tutorial on driving to a detected object!
Real World Example
FTC Team Hazen Robotics has implemented code that can drive to a game element:
https://github.com/HazenRobotics/freight-frenzy/blob/master/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/utils/TargetPositionCalculator.java https://github.com/HazenRobotics/freight-frenzy/blob/master/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/vision/HomographyTargetDistance.java